<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;

        }

        body,
        html {
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .box {
            width: 600px;
            height: 600px;
            /* background-color: brown; */
        }

        div input {
            height: 40px;
            padding-left: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            width: 100%;
            outline: none;
            box-sizing: border-box;
            margin-top: 30px;
        }

        .blu {
            background-color: blue;
            color: #fff;
        }
    </style>
</head>

<body>
    <div class="box">
        <div>
            <input type="username" placeholder="输入用户名">
        </div>
        <div>
            <input type="password" placeholder="密码">
        </div>
        <div>
            <input type="password" placeholder="确认密码">
        </div>
        <input type="button" value="注册" class="blu">
    </div>

</body>

</html>
<script src="./ajax.promise.js"></script>
<script>
    var input = document.querySelectorAll('input')

    input[3].onclick = function () {
        if (input[0].value && input[1].value && input[2].value) {
            if (input[1].value == input[2].value) {
                if (/^\d{4}$/.test(input[1].value)) {
                    ajax('get', 'https://yantianfeng.com/api/register', {
                        username: input[0].value,
                        password: input[1].value,
                    }).then((data) => {
                        console.log(data);
                    })
                } else {
                    alert('请求正确的手机号/密码')
                }
            } else {
                alert('两次密码不一致')
            }

        } else {
            alert('密码不能为空！')
        }
    }
</script>